package com.eastjet.equipment.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eastjet.equipment.mapper.DeviceAcceptanceMapper;
import com.eastjet.equipment.service.DeviceAcceptanceService;
import com.eastjet.equipment.util.PageUtil;
import com.eastjet.equipment.util.RedisUtil;
import com.eastjet.maintenance.domain.DeviceAcceptance;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 杨博文
* @description 针对表【device_acceptance(验收管理表)】的数据库操作Service实现
* @createDate 2024-11-25 09:23:37
*/
@Service
public class DeviceAcceptanceServiceImpl extends ServiceImpl<DeviceAcceptanceMapper, DeviceAcceptance>
    implements DeviceAcceptanceService {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private DeviceAcceptanceMapper deviceAcceptanceMapper;

    @Override
    public Page<DeviceAcceptance> getAcceptanceList(int page, int size, String condition) {
        // 定义Redis中的键
        String redisKey = "AcceptanceList";
        System.out.println("查询Acceptance-condition:"+condition);
        // 先查缓存Redis
        if (redisUtil.hasKey(redisKey)) {
            System.out.println(1);
            System.out.println("在redis缓存中查询DeviceClass");
            List<DeviceAcceptance> deviceAcceptances;
            if (condition != null  && !condition.isEmpty() && condition !="") {
                System.out.println(2);
                deviceAcceptances = deviceAcceptanceMapper.selectByCondition(condition); // 获取所有数据


            } else {
                System.out.println(3);
                deviceAcceptances  = (List<DeviceAcceptance>) redisUtil.get(redisKey);
            }
            // 使用PageUtil进行分页
            return PageUtil.paginate(deviceAcceptances, page, size);
        } else {
            System.out.println(4);
            System.out.println("在数据库中查询SupplierList");
            List<DeviceAcceptance> deviceAcceptances;
            // 根据condition条件查询
            if (condition != null && !condition.isEmpty() && condition !="") {
                System.out.println(5);
                deviceAcceptances = deviceAcceptanceMapper.selectByCondition(condition);
            } else {
                System.out.println(6);
                condition="";
                deviceAcceptances = deviceAcceptanceMapper.selectByCondition(condition); // 获取所有数据
                // 将数据存入Redis
                redisUtil.set(redisKey, deviceAcceptances);
            }
            // 使用PageUtil进行分页
            return PageUtil.paginate(deviceAcceptances, page, size);
        }
    }

    
}




